<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /*  let zh = {};
         let obj = new Object();
         console.log(obj.__proto__ == zh.__proto__); // true
         console.log(zh.__proto__ == Object.prototype); // true
         let arr = [];
         console.log(arr.__proto__ == Array.prototype);// true
         let str = '';
         console.log(str.__proto__ == String.prototype); // true */

        // 设置原型
        let user = { name: '李思' };
        let parent = {
            name: '李思他爹',
            show() {
                console.log('parent的show方法')
            }
        };

        Object.setPrototypeOf(user, parent);
        user.show(); // 将parent设置为user的原型

        // 获取原型
        console.log(Object.getPrototypeOf(user)); // parent对象

        function User(name) {
            this.name = name;
        }
        // 添加方法
        User.prototype = {
            constructor: User,//指定User.prototype的构造函数
            show() {
                console.log(this.name);
            },
            add(){
                console.log('新增方法')
            }
        }
        let zh = new User.prototype.constructor('王武');
        zh.show();
        zh.add();
    </script>
</body>

</html>